<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="num1" />
    <select name="" id="calc">
      <option value="+">+</option>
      <option value="-">-</option>
      <option value="*">*</option>
      <option value="/">/</option>
    </select>
    <input type="text" id="num2" />
    <button id="btn">计算</button>
    结果:<input type="text" id="res1" />
    <!-- 声明input框 -->
    <script>
      var num1Ele = document.getElementById("num1");
      var num2Ele = document.getElementById("num2");
      //   var butEle = document.getElementById("btn");
      var reason = document.getElementById("res1");
      var calcEle = document.getElementById("calc");
      //  获取input框的值 返回值为一个元素节点(节点:是一个对象  包含name value各种值)
      btn.onclick = function () {
        //获取各个节点的对应需要的值
        var num1 = parseInt(num1Ele.value);
        var num2 = parseInt(num2Ele.value);
        var calc = calcEle.value;
        var tmp;
        //保存运算结果

        //获取输入的值
        if (calc == "+") {
          tmp = num1 + num2;
        } else if (calc == "-") {
          tmp = num1 - num2;
        } else if (calc == "*") {
          tmp = num1 * num2;
        } else if (calc == "/") {
          tmp = num1 / num2;
        }
        reason.value = tmp;
        //运算结果赋值给reason显示
      };
    </script>
  </body>
</html>
